package com.example.demo3.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo3.entity.Hazard;
import com.example.demo3.mapper.HazardMapper;
import com.example.demo3.mapper.SparePartsMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 危险源及措施 服务实现类
 * </p>
 *
 * @author xsyuan
 * @since 2020-03-27
 */
@Service
public class HazardService extends ServiceImpl<HazardMapper, Hazard>{

    @Resource
    private SparePartsMapper sparePartsMapper;
    @Resource
    private HazardMapper hazardMapper;

    /**
     * 分页查询
     * @param pageindex
     * @param pagesize
     * @return
     */
    public Page<Hazard> getSelectPage(int pageindex, int pagesize){
        Page<Hazard> page=new Page<Hazard>().setCurrent(pageindex).setSize(pagesize);
        QueryWrapper<Hazard> queryWrapper=new QueryWrapper<Hazard>()
                .orderByDesc("CODE");
        hazardMapper.selectPage(page,queryWrapper);
        return page;
    }

    public int countPage(Map<Object,Object> map){
        return hazardMapper.countPage(map);
    }

    public List<Hazard> queryPage(Map<Object,Object> map){
        return hazardMapper.queryPage(map);
    }
    /**
     * 新增
     * @param hazard
     */
    public void insert(Hazard hazard){
        hazard.setId(sparePartsMapper.getUUID());
        hazardMapper.insert(hazard);
    }

    /**
     *修改
     * @param hazard
     */
    public void update(Hazard hazard){
        hazardMapper.updateById(hazard);
    }

    /**
     * 删除
     * @param id
     */
    public void delete(String id){
        QueryWrapper<Hazard> queryWrapper = new QueryWrapper<Hazard>()
                .eq("ID",id);
        hazardMapper.delete(queryWrapper);
    }

    /**
     * @description  通过Map查询【危险源及措施】集合
     * @author: xsyuan
     * @date: 2020/3/28 10:51
     * @param  map
     * @return  List
     */
    public List<Hazard> getByMap(Map<String,Object> map){
        return hazardMapper.findByMap(map);
    }
}
